<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title site-title">
		<legend>
			<a name="fixbar" style="font-size: 16px; color: #ce2424;">在线课堂</a>
		</legend>
	</fieldset>
	<script type="text/html" id="toolbarDemos">
		<form class="layui-form" action="save" id="myForm" method="post" lay-filter="stuform">
		<input type="text" style="display: none;" />
			<div class="layui-inline">
				<label class="layui-form-label" style="width:100px">查询内容:</label>
				<div class="layui-input-block">
					<input type="text" name="search" id="searchvalue" value="${search}" onkeypress="return onKeyPress(event)" class="layui-input" />
				</div>
			</div>
			<div class="layui-inline">
				<button class="layui-btn layui-btn-sm" onclick="searchs()" style="margin-left: 16px"><i class="fa fa-search"></i>查询</button>
			</div>
		</form>
	</script>
	<table class="layui-hide" id="filevideo" lay-filter="filevideo"></table>
	<script type="text/javascript">
		var option={
			elem:'#filevideo',
			title:'课件资源',
			path:'filevideo',
			toolbar: '#toolbarDemos',
			addurl:'edit',
			limit: 20,
			defaultToolbar: ['filter'],
			cols: [[
				{field: 'filename',align:'center', title: '课程名称',templet: function(d){
					return d.sysfile.tbCurriculum?d.sysfile.tbCurriculum.courseName:"";
					}
				},
				{field: 'filename',align:'center',hide:true, title: '课件名称',templet: function(d){
					return d.sysfile?d.sysfile.filename:"";
					}
				},
				{field: 'resourceprofile',align:'center', title: '课件简介',templet: function(d){
					return d.sysfile?d.sysfile.resourceprofile:"";
				}},
				{field: 'reasonforfilevideo',align:'center',width:200, title: '下载',templet: function(d){
					if(d.sysfile.filetypename=="课件资源"){
						return d.sysfile.uuid?'<a class="layui-btn layui-btn-normal layui-btn-xs" data-method="notice" lay-event="downloadfile" >点击下载</a>':"";
					}else if(d.sysfile.filetypename=="课件视频资源"){
						return d.sysfile.uuid?'<a class="layui-btn layui-btn-primary layui-btn-xs" data-method="notice" lay-event="voide" >点击观看</a><a class="layui-btn layui-btn-normal layui-btn-xs" data-method="notice" lay-event="downloadfile" >点击下载</a>':"";
					}else{
						return d.sysfile.uuid?'<a class="layui-btn layui-btn-normal layui-btn-xs" data-method="notice" lay-event="downloadfile" >点击下载</a>':"";
					}
					
				}}
			]] 
		}
		var currRow='${param.currRow==null?null:param.currRow}';
		var limit=${param.limit==null?'null':param.limit};
		var page=${param.page==null?'null':param.page};
		var classTable=new LayUiTable(option,currRow,limit,page);
		classTable.init();
		layui.use('table', function(){
			var table = layui.table;
			table.on('tool(filevideo)', function(obj){
			    if(obj.event === 'voide'){
			    	$.post("filevideo/voide", {uuid: obj.data.sysfile.uuid}, function(data){
						layui.use('layer', function(){
							layer.open({
								title: obj.data.sysfile.filename,
								type: 1,
	    	      				shade: 0.3,
	    	      				shadeClose:false,
	    	      				maxmin: true,
	    	      				content: data,
	    	      				area: '905px',
	    	      				yes:function(){
	    	      					layer.closeAll();
	    	      				},
							})
						});
					});
			    }
			    if(obj.event === 'downloadfile'){
			    	$.post('downloadfile',{uuid:obj.data.sysfile.uuid},function(data){
						if(data){
							window.location.href="download?uuid="+obj.data.sysfile.uuid;
						}else{
							layer.msg("此文件已不存在，无法下载！");					
						}
					});
			    }
			});
		});
		function searchs(){
			classTable.search();
		}
		function empty(){
			classTable.empty();
		} 
		function onKeyPress(event){
			if(event.keyCode==13){
				searchs();
			}
		}
	</script>
	<script type="text/javascript">
		function downloadfile(value){
			
		}
	</script>
</body>
</html>